<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Registration Page</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      margin: 0;
    }

  .registration-container {
      background-color: white;
      padding: 20px;
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
      width: 350px;
    }

    h2 {
      text-align: center;
    }

    label {
      display: block;
      margin-bottom: 5px;
    }

    input {
      width: 100%;
      padding: 8px;
      margin-bottom: 15px;
      border: 1px solid #ccc;
      border-radius: 3px;
    }

    button {
      background-color: #007bff;
      color: white;
      padding: 10px 15px;
      border: none;
      border-radius: 3px;
      cursor: pointer;
      width: 100%;
    }

    button:hover {
      background-color: #0056b3;
    }
  </style>
</head>

<body>
  <div class="registration-container">
    <h2>Registration</h2>
    <form id="registrationForm">
      <label for="username">Username:</label>
      <input type="text" id="username" required>
      <label for="password">Password:</label>
      <input type="password" id="password" required>
      <label for="confirmPassword">Confirm Password:</label>
      <input type="password" id="confirmPassword" required>
      <label for="email">Email:</label>
      <input type="email" id="email" required>
      <button type="submit">Register</button>
    </form>
  </div>
  <script>
    document.getElementById('registrationForm').addEventListener('submit', function (e) {
      e.preventDefault();
      var username = document.getElementById('username').value;
      var password = document.getElementById('password').value;
      var confirmPassword = document.getElementById('confirmPassword').value;
      var email = document.getElementById('email').value;

      if (password!== confirmPassword) {
        alert('Passwords do not match.');
        return;
      }

      // 这里可以添加向服务器发送注册数据的逻辑，例如使用fetch API
      // 假设后端接口为 /register，数据格式为JSON
      fetch('/homepage/register/src/registerMain.exe', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ username: username, password: password, email: email })
      })
	  .then(response => response.json())
      .then(data => {
            <!-- const resultDisplay = document.getElementById('result-display'); -->
            if (data.success) {
              //resultDisplay.innerHTML = `<p>登录成功！欢迎 ${data.message}。</p>`;
				window.location.href = '/homepage/login';
            } else {
              //resultDisplay.innerHTML = `<p>登录失败：${data.message}</p>`;
				alert('register failed. Please check your username and password.');
			}
          });
    });
  </script>
</body>

</html>